package com.blb.thread;

/**
 * 守护线程
 */
public class DaemonDemo {

    public static void main(String[] args) {
        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println(Thread.currentThread().getName() + "------>" + i);
                try {
                    Thread.sleep(1000L);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        thread1.setName("张三");
        thread1.setPriority(Thread.MIN_PRIORITY);


        Thread thread2 = new Thread(() -> {
            for (int i = 0; i >=0; i++) {
                System.out.println(Thread.currentThread().getName() + "------>" + i+"我守护你们");
                try {
                    Thread.sleep(1000L);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        thread2.setName("李四三");
        thread2.setPriority(Thread.MIN_PRIORITY);
//        thread2.setDaemon(true);


        thread1.start();
        thread2.start();
    }




}
